<template>
  <div class="ele-body">
    <el-card shadow="never">
      <!-- 表格工具栏 -->
      <div class="ele-table-tool">
        <div class="ele-table-tool-title">流程单</div>
      </div>
      <!-- 数据表格 -->
      <ele-data-table ref="table" :config="table" :choose.sync="choose" :border="true">
        <template>
          <el-table-column prop="name" label="单据名称" sortable show-overflow-tooltip min-width="110" />
          <el-table-column prop="ticket_name" label="预留" sortable show-overflow-tooltip min-width="110" />
          <el-table-column prop="status" label="流程状态" sortable show-overflow-tooltip min-width="110" />
          <el-table-column prop="createtime" label="创建时间" sortable show-overflow-tooltip min-width="135">
            <template slot-scope="{row}">{{ row.createtime | toDateString }}</template>
          </el-table-column>
          <el-table-column prop="updatetime" label="更新时间" sortable show-overflow-tooltip min-width="135">
            <template slot-scope="{row}">{{ row.updatetime | toDateString }}</template>
          </el-table-column>
          <el-table-column label="操作" align="center" min-width="160" fixed="right">
            <template slot-scope="{row}">
              <el-link icon="el-icon-edit" type="primary" :underline="false" @click="edit(row)">修改状态</el-link>
              <el-link icon="el-icon-finished" type="primary" :underline="false" @click="jump(row)">流程详情
              </el-link>
            </template>
          </el-table-column>
        </template>
      </ele-data-table>
    </el-card>
    <el-dialog
      title="修改状态"
      width="600px"
      :visible.sync="isShow"
      :close-on-click-modal="false"
      :destroy-on-close="true"
      :lock-scroll="false"
      @closed="editForm = { status: 'pass'}"
    >
      <el-form
        ref="editForm"
        :model="editForm"
        label-width="82px"
        @submit.native.prevent
      >
        <el-form-item label="是否确认：" prop="name">
          <el-radio v-model="editForm.status" label="pass">通过</el-radio>
          <el-radio v-model="editForm.status" label="deny">拒绝</el-radio>
        </el-form-item>
        <el-form-item label="操作描述：">
          <el-input
            v-model="editForm.description"
            placeholder="请输入操作描述"
            :rows="4"
            type="textarea"
          />
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button @click="isShow = false">取消</el-button>
        <el-button
          type="primary"
          :loading="editLoading"
          @click="save"
        >保存</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: 'TaskWorkflow',
  data() {
    return {
      table: { // 表格配置
        url: '/workflow/ticket/list/task/',
        where: {}
      },
      choose: [], // 表格选中数据
      isShow: false,
      editForm: {
        status: 'pass'
      },
      editLoading: false,
      current: {}
    }
  },
  methods: {
    /* 获得当前操作列 */
    edit(row) {
      this.isShow = true
      this.current = row
    },
    /* 保存操作 */
    save() {
      this.editLoading = true
      const url = `/workflow/ticket/action/${this.editForm.status}/${this.current.id}/`
      this.$http.post(url, { description: this.editForm.description }).then(res => {
        this.editLoading = false
        const { data } = res
        if (data.code === 0) {
          this.$message({ message: data.msg, type: 'success' })
          this.$refs.table.reload()
          this.isShow = false
        } else {
          this.$message({ message: data.msg, type: 'error' })
        }
      })
    },
    /* 跳转详情页 */
    jump(row) {
      this.$router.push(`/task/detial/${row.id}`)
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
